package cn.mylearn.tools.encryption;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.HashRequest;

/**
 * 
 * @author cnhon
 *
 */
public class ShiroEncryption {
	//盐长
	public static final int SALT_SIZE=4;
	//迭代次数
	public  static final int ITERATIONS=1024;
	//加密方式
	public static final String ENCRYPWAY_1="SHA-1";
	public static final String ENCRYPWAY_256="SHA-256";
	public static final String ENCRYPWAY_512="SHA-512";
	
	//sha salt 加密
	public static String shaSaltPassWord(String password,String salt){
		//密码
		DefaultHashService hashService = new DefaultHashService(); //默认算法 SHA-512
		//传入算法、数据、公盐、迭代次数
		HashRequest request = new HashRequest.Builder()
				.setAlgorithmName(ENCRYPWAY_512).setSource(password)
				.setSalt(salt).setIterations(ITERATIONS).build();
		return hashService.computeHash(request).toHex();
	}
	
	//16进制盐
	public static String salt(){
		SecureRandomNumberGenerator random=new SecureRandomNumberGenerator();
		String hex=random.nextBytes(SALT_SIZE).toHex();
		return hex;
	}
	

	
	
}





